<template>
  <el-dialog :title="info.title" v-if="visible" :visible.sync="visible" center width="460px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="100px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="24">
          <el-form-item label="日期" prop="day">
            <p :v-model="form.day"> {{this.form.day}}</p>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="类型" prop="type">
            <el-select
              v-model="form.type"
              size="small"
              filterable
              style="width: 100%"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in types"
                :key="item.key"
                :label="item.value"
                :value="item.key"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input type="textarea" :rows="4" v-model="form.remark" size="small" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="warning" size="small" @click="handleEditDel()">撤 销</el-button>
            <el-button type="primary" size="small" @click="handleEditAdd()">保 存</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { addHoliday, revokeHoliday } from '@/api/base/holiday'
import form from '@/utils/form'

export default {
  extends: form,
  props: {
    reqAdd: {
      default: addHoliday,
      type: Function
    },
    reqUpd: {
      default: revokeHoliday,
      type: Function
    },
    info: {
      type: Object,
      default: null
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  data() {
    return {
      types: [{key: 1, value: '普休'}, {key: 2, value: '国假'}],
      rules: {
        day: [{ required: true, trigger: 'blur', message: '日期不可为空' }],
        type: [{ required: true, trigger: 'blur', message: '类型不可为空' }]
      },
      visible: false
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.init()
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {
    init() {
      this.$set(this, 'form', {})
      this.$set(this.form, 'day', this.info.edit.day)
      if(this.info.edit.holiday === ''){
        this.$set(this.form, 'remark', '')
      }else{
        this.$set(this.form, 'type', this.info.edit.holiday.type)
        this.$set(this.form, 'remark', this.info.edit.holiday.remark)
      }
    },
    handleEditDel() {
      this.$set(this.info, 'type', 'revoke')
      this.handleEdit()
    },
    handleEditAdd(e) {
      this.$set(this.info, 'type', 'add')
      this.handleEdit()
    }
  }
}
</script>

<style>

</style>
